package com.qys.livesMall.system.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.system.enums.SystemMessageEnum;
import com.qys.livesMall.system.model.dto.sys.PlatformInfoDto;
import com.qys.livesMall.system.model.dto.sys.PlatformInfoQueryPackageDto;
import com.qys.livesMall.system.model.vo.sys.PlatformInfoVO;
import com.qys.livesMall.system.service.IH2PlatformInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jodd.util.StringUtil;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 平台信息发布 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-07-05
 */
@Tag(name = "平台信息", description = "平台信息")
@RestController
@RequestMapping("/sys/platformInfo")
public class H2PlatformInfoController {

    @Resource
    private IH2PlatformInfoService ih2PlatformInfoService;

    @Operation(summary = "添加平台信息")
    @PostMapping("/add")
    public R add(@RequestBody @Validated PlatformInfoDto platformInfoDto){
        if (platformInfoDto.getTypeInfo()==1 && StringUtil.isBlank(platformInfoDto.getTarget())){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_target);
        }
       return ih2PlatformInfoService.add(platformInfoDto)? R.ok():R.fail();
    }

    @Operation(summary = "修改平台信息")
    @PostMapping("/update")
    public R update(@RequestBody @Validated PlatformInfoDto platformInfoDto){
        if (null == platformInfoDto.getId()){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_ID);
        }
        if (platformInfoDto.getTypeInfo()==1 && StringUtil.isBlank(platformInfoDto.getTarget())){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_target);
        }
        return ih2PlatformInfoService.update(platformInfoDto)? R.ok():R.fail();
    }

    @Operation(summary = "删除平台信息")
    @DeleteMapping(value = "/delete/{id}")
    public R delete(@PathVariable Long id){
        ih2PlatformInfoService.removeById(id);
        return R.ok();
    }

    @Operation(summary = "查询平台信息列表")
    @PostMapping("query")
    public R<IPage<PlatformInfoVO>> query(@RequestBody @Validated PlatformInfoQueryPackageDto dto){
        return R.ok(ih2PlatformInfoService.query(dto));
    }

    @Operation(summary = "查询平台信息详情")
    @GetMapping(value = "/info/{id}")
    public R<PlatformInfoVO> info(@PathVariable Long id){
        return R.ok(ih2PlatformInfoService.info(id));
    }
}
